package logic

import (
	"context"
	"srv/internal/svc"
	"srv/models/mysqlinit"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type AdmUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAdmUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdmUserLogic {
	return &AdmUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AdmUserLogic) AdmUser(in *srv.AdmUserRequest) (*srv.AdmUserResponse, error) {
	// todo: add your logic here and delete this line
	var u []mysqlinit.User
	if in.UserId == 0 {
		mysqlinit.DB.Debug().Find(&u)
	} else {
		mysqlinit.DB.Debug().Where("id = ?", in.UserId).Find(&u)
	}

	var list []*srv.AdmUser
	for _, m := range u {
		listHouse := srv.AdmUser{
			UserId:      int64(m.ID),
			Real:        m.Real,
			IdCord:      m.IdCord,
			StraightUrl: m.StraightUrl,
			ReverseUrl:  m.ReverseUrl,
			Status:      int64(m.Status),
		}
		list = append(list, &listHouse)
	}
	return &srv.AdmUserResponse{
		List: list,
	}, nil
}
